package com.LatitudeYao;


/**
 * Created by GTS on 2017/8/21.
 * 通过Runnable实例方式进行创建
 */
class RuunableDemo implements Runnable {
    private Thread t;
    private String theadName;
    RuunableDemo(String name){
        theadName = name;
        System.out.println("创建   "+theadName);
    }

    public void run(){
        System.out.println("运行    "+theadName);
        try{
            for (int i = 4; i > 0 ; i--) {
                System.out.println("Thread     "+theadName+"  i");
                Thread.sleep(50);
            }
        }
        catch (InterruptedException e){
            System.out.println("线程 " + theadName + " 中断");
        }
        System.out.println("线程 " + theadName + " 退出");
    }
    public void start(){
        System.out.println("Starting " + theadName);
        if(t == null){
            t =new Thread(this,theadName);
            t.start();
        }
    }
}
public class TestThread{
    public static void main(String[] args) {
        RuunableDemo r1 = new RuunableDemo("Thread-1");
        r1.start();
        RuunableDemo r2 = new RuunableDemo("Thread-2");
        r2.start();
    }

}
